<template>
	<view class="resetPassword">
		<!-- 手机号 - 密码 - 验证码 -->
		<view class="main">
			<view class="tips">若你忘记了密码，可在此重置新密码。</view>
			<view class="item">
				<input class="ipt" type="number" placeholder="请输入手机号码" v-model="phone" />
			</view>
			<view class="item">
				<input class="ipt" type="text" placeholder="请输入新密码" v-model="password" :password="isShow"/>
				<view class="icon" :class=" isShow ? 'icon1':'icon2' " @tap="passwordEvents"></view>
			</view>
			<view class="item">
				<input class="ipt" type="number" placeholder="验证码" v-model="code" />
				<view class="text">获取重置码</view>
			</view>
		</view>
		<!-- 重置密码 -->
		<view class="btn" @tap="reset">
			重置密码
		</view>
	</view>
</template>

<script>
	import { resetPassword } from "../../../api/user/index.js"
	export default {
		data() {
			return {
				phone:'17596496508', // 重置密码 - 手机号
				password:'123456', // 重置密码 - 密码
				code:'1234', // 重置密码 - 验证码
				isShow: true, // 密码 + 图标 - 显示|隐藏
				username: '', // 用户名
			};
		},
		methods:{
			// 密码图标 - 显示|隐藏
			passwordEvents(){
				this.isShow = !this.isShow
			},
			// 重置密码
			reset(){
				this.username = uni.getStorageSync("userInfo").username;
				resetPassword(this.username).then(res=>{
					// 跳转 - 登录
					if(res.data.success){
						uni.showToast({
							title: "修改成功"
						});
						setTimeout(function(){
							uni.navigateTo({
								url: "../login/login"
							})
						},1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
@import './index.scss'
</style>
